<template>
  <div class="ma-content-block lg:flex justify-between">
    <!-- CRUD 组件 -->
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :sm="8" :xs="24">
          <a-form-item field="uuid" label="用户ID">
            <a-input v-model="searchForm.uuid" placeholder="请输入用户ID" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item field="user_keyword" label="用户信息搜索">
            <a-input v-model="searchForm.user_keyword" placeholder="请输入用户手机号/昵称" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :sm="8" :xs="24">
          <a-form-item field="status" label="投诉状态">
            <sa-select v-model="searchForm.status" dict="complaint_status"></sa-select>
          </a-form-item>
        </a-col>
       
      </template>

      <!-- Table 自定义渲染 -->
      <!-- 状态列 -->
       <template #id="{ record }">
        {{ record.uuid }}/{{ record.nickname }}
      </template>
      <template #image="{ record }">
        <div style="display: flex;align-items: center;">
          <div v-for="value in splitString(record.image)" style="margin-right: 5px;">
            <a-image :src="value" :preview-src-list="[value]" width="50px" height="50px" />
          </div>
        </div>
        
      </template>
      <template #operationAfterExtend="{ record }">
        <a-popconfirm
          content="确定要标记为已处理吗?"
          position="bottom"
          @ok="passAction(record)">
          
          <a-button v-if="record.status === 2" type="primary">
            处理
          </a-button>
        </a-popconfirm>
        
      </template>
      
    </sa-table>

    
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import api from '@/api/leader'

const crudRef = ref()
// 搜索表单
const searchForm = ref({
  uuid: '',
  user_keyword: '',
  status: '',
})

const seatForm = ref({
  log_id: '',
  fail_reason: '',
  status: 3,
})


// SaTable 基础配置
const options = reactive({
  api: api.complaintList,
  rowSelection: { showCheckedAll: true },
})

// SaTable 列配置
const columns = reactive([
  { title: '用户ID/昵称', dataIndex: 'id', width:180 },
  { title: '联系电话', dataIndex: 'phone', width: 150 },
  { title: '投诉凭证', dataIndex: 'image',width: 160 },
  { title: '投诉内容', dataIndex: 'content', width: 200 },
  { title: '申请时间', dataIndex: 'created_at', width: 180 },
  { title: '投诉状态', dataIndex: 'status', type: 'dict', dict: 'complaint_status', width: 100 },
])

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

const passAction = async (record) => {
  await api.complaintAudit({ log_id: record.id})
  Message.success('操作成功')
  refresh()
}


// 把字符串通过，分割成数组
const splitString = (str) => {
  console.log('splitString', str)
  if (!str) {
    return []
  }
  return str.split(',')
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
